package edu.fasta.sisinfo2.gui;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

import edu.fasta.sisinfo2.net.Cliente;
import edu.fasta.sisinfo2.poker.PokerControllerCliente;



public class Connect {
	private JDialog ventana = new JDialog();
	private JPanel contentPane = new JPanelFondo("/Img/Login2.png",0,0);
	private JTextField campoIP;
	private JTextField campoPuerto;
	private Icon c1 = new ImageIcon(getClass().getResource( "/Img/conectar1.png" ));
	private Icon c2 = new ImageIcon(getClass().getResource( "/Img/conectar2.png" ));
	private Icon c3 = new ImageIcon(getClass().getResource( "/Img/conectar3.png" ));
	private Icon s1 = new ImageIcon(getClass().getResource( "/Img/Salir1.png" ));
	private Icon s2 = new ImageIcon(getClass().getResource( "/Img/Salir2.png" ));
	private Icon s3 = new ImageIcon(getClass().getResource( "/Img/Salir3.png" ));
	private Cliente cliente;
	private PokerControllerCliente PKC = new PokerControllerCliente();
	
	public Connect(PokerControllerCliente unPCC){
		this.setPKC(unPCC);
		ventana.setTitle("Texas UFasta - Conector");	
		ventana.setSize(321, 218);
		ventana.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		ventana.getContentPane().add(contentPane);
		ventana.setResizable(false);
		ventana.setLocationRelativeTo(null);
		contentPane.setLayout(null);
		JButton okButton = new JButton( "", c1 );
		okButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				setCliente(new Cliente(getCampoIP().getText(), Integer.parseInt(getCampoPuerto().getText())));
				ventana.dispose();
				getPKC().setCliente(cliente);
				getPKC().start();
			}			
		});
		okButton.setBounds(43, 105, 114, 39);
		okButton.setRolloverIcon( c2 );
		okButton.setPressedIcon(c3);
		okButton.setBorder(BorderFactory.createEmptyBorder());
		okButton.setContentAreaFilled(false);
		contentPane.add(okButton);
		okButton.setDefaultCapable(true);
		ventana.getRootPane().setDefaultButton(okButton);
		JButton cancelButton = new JButton( "", s1 );
		cancelButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
		cancelButton.setRolloverIcon( s2 );
		cancelButton.setPressedIcon(s3);
		cancelButton.setBorder(BorderFactory.createEmptyBorder());
		cancelButton.setContentAreaFilled(false);
		cancelButton.setBounds(173, 105,114, 39);
		contentPane.add(cancelButton);
		
		campoIP = new JTextField();
		campoIP.setText("localhost");
		campoIP.setBounds(118, 41, 182, 20);
		contentPane.add(campoIP);
		campoIP.setColumns(10);
		
		campoPuerto = new JTextField();
		campoPuerto.setText("35000");
		campoPuerto.setBounds(118, 74, 182, 20);
		contentPane.add(campoPuerto);
		campoPuerto.setColumns(10);
		
		JLabel lblIngresarDireccionIp = new JLabel("Ingresar los datos del servidor");
		lblIngresarDireccionIp.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblIngresarDireccionIp.setForeground(Color.WHITE);
		lblIngresarDireccionIp.setBounds(73, 13, 183, 14);
		contentPane.add(lblIngresarDireccionIp);
		
		JLabel lblIp = new JLabel("IP");
		lblIp.setBounds(63, 43, 45, 14);
		contentPane.add(lblIp);
		
		JLabel lblPuerto = new JLabel("Puerto");
		lblPuerto.setBounds(55, 76, 63, 14);
		contentPane.add(lblPuerto);
		
		JLabel estado = new JLabel("");
		estado.setBounds(37, 155, 258, 14);
		contentPane.add(estado);
		ventana.setVisible(true);
	}

	public JTextField getCampoIP() {
		return campoIP;
	}

	public void setCampoIP(JTextField campoIP) {
		this.campoIP = campoIP;
	}

	public JTextField getCampoPuerto() {
		return campoPuerto;
	}

	public void setCampoPuerto(JTextField campoPuerto) {
		this.campoPuerto = campoPuerto;
	}

	public Cliente getCliente() {
		return cliente;
	}

	public void setCliente(Cliente cliente) {
		this.cliente = cliente;
	}

	public PokerControllerCliente getPKC() {
		return PKC;
	}

	public void setPKC(PokerControllerCliente pKC) {
		PKC = pKC;
	}
	
}
